define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cookie_analyze/index' + location.search,
                    add_url: 'cookie_analyze/add',
                    edit_url: 'cookie_analyze/edit',
                    del_url: 'cookie_analyze/del',
                    multi_url: 'cookie_analyze/multi',
                    import_url: 'cookie_analyze/import',
                    table: 'cookie_analyze',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'updated_at',
                search: false, //是否启用快速搜索
                columns: [
                    [
                        // {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'updated_at', title: __('使用时间')},
                        {field: 'job_id', title: __('Job_id')},
                        {field: 'job_table', title: __('Job_table'), operate: 'LIKE'},
                        {field: 'job_ip', title: __('Job_ip'), operate: 'LIKE'},
                        {field: 'job_city', title: __('任务地区'), operate: 'LIKE'},
                        // {field: 'use_time', title: __('Use_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'type', title: __('cookie 类型'), operate: 'LIKE'},
                        {field: 'device_memory', title: __('Device_memory')},
                        {field: 'hardware_concurrency', title: __('频率')},
                        {field: 'unmasked_renderer', title: __('渲染器'), operate: 'LIKE'},
                        {field: 'unmasked_vendor', title: __('供应商'), operate: 'LIKE'},
                        {field: 'fingerprint', title: __('Fingerprint'), operate: 'LIKE'},
                        {
                            field: 'use_state',
                            title: __('Use_state'),
                            operate: false,
                            // cellStyle: Controller.api.formatter.css,
                            formatter:function (value,row) {
                                if(row.use_state == 0){
                                    return 0;
                                }else{
                                    console.log(JSON.parse(row.use_state));
                                    return '状态&nbsp;&nbsp;&nbsp;<i class="fa fa-question-circle-o" onmouseenter="roleupdate(this)" onmouseleave="roleupdate2(this)" data-id="'+row.id+'" ></i>';
                                    // return 1;
                                }
                            }
                        },

                        // {field: 'use_state', title: __('Use_state'), operate: 'LIKE',formatter:},
                        // {field: 'created_at', title: __('Created_at')},

                        // {field: 'created_at',text:'使用记录', title: __('操作'),
                        //     addclass:'btn-addtabs',
                        //     formatter:Table.api.formatter.addtabs,url:function(row){
                        //         return '/tTrHFCUqIV.php/cookie_records?ana_id='+row.id;
                        //     },
                        //     // button:[]
                        //     // formatter:function (value,row) {
                        //     //     var url_str = '/tTrHFCUqIV.php/cookie_records?ana_id='+row.id;
                        //     //     return Fast.api.addtabs(url_str,"使用记录");
                        //     //     return '<a  href="'+url_str+'">使用记录</a>';
                        //     // }
                        // },

                        {
                            field: 'operate', title: __('Operate'), table: table,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: '使用记录',
                                    title: '使用记录',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-primary btn-addtabs',
                                    url:function(row){
                                        return '/tTrHFCUqIV.php/cookie_records?ana_id='+row.id;
                                    }
                                }
                            ],
                            formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                $(table).data("operate-edit", null); // 列表页面隐藏 .编辑operate-edit  - 删除按钮operate-del
                                $(table).data("operate-del", null); // 列表页面隐藏 .编辑operate-edit  - 删除按钮operate-del
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            },
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };

    return Controller;
});

// Fast.api.addtabs("/tTrHFCUqIV.php/cookie_records","使用记录详情");

function redict(url) {
    Fast.api.addtabs(url,"使用记录");
}

function roleupdate(e){
    $(e).addClass('fa-question-circle');
    $(e).removeClass('fa-question-circle-o');
    var id = $(e).attr('data-id');
    var fa_this = $(e);

    var str2 = '名称：状态</br>';
    $.post({
        async:true,
        url: "cookie_analyze/get_cookie_analyze_json",
        data:{'id':id},
        success: function(res3){
            $.each(res3.data, function (k2, v2) {
                str2 += k2+' ：'+v2+'</br>';
            });
            // console.log($(e));
            layer.tips(
                "<span style='color:black'>"+str2+"</span>",
                fa_this,
                {
                    area: ['300px', 'auto'],
                    // area: 'auto',
                    tips: [2, '#fff'],
                    time: 30000
                }
            );

        }
    });

}

function roleupdate2(e){
    $(e).addClass('fa-question-circle-o');
    $(e).removeClass('fa-question-circle');
    layer.closeAll();
}
